from django.db import models
# Create your models here.
from django.core.paginator import ObjectPaginator, InvalidPage

class Product(models.Model):
    name = models.CharField(blank=False, null=False, maxlength=50)
    image = models.ImageField(upload_to='images', blank=True, null=True)
    text = models.TextField()
    pub_date = models.DateTimeField()
    
    def __str__(self) :return self.name
    def short_desp(self): return self.text[:50]
    class Admin: pass

class New(models.Model):
    title = models.CharField(blank=False, null=False, maxlength=50)
    content = models.TextField()
    pub_date = models.DateTimeField()
    
    def __str__(self):
        return self.title
    def datestr(self):
        dt = self.pub_date
        return "%s %s-%s"%(dt.year, dt.month, dt.day)
    
    class Meta:
        ordering = ('-pub_date', )
        get_latest_by = 'pub_date'
        
    class Admin: pass
